import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
  plugins: [vue()],
  // define: {
  //   "process.env": {}, // 这里可以根据需要添加具体的环境变量定义
  // },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: "0.0.0.0",
    port: 3000,
    cors: true,
    proxy: {
      "/amap": {
        target: "https://restapi.amap.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/amap/, ""),
        // 确保配置正确
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            console.log("🚀 代理请求:", req.url, "->", proxyReq.path);
          });
          proxy.on("error", (err, req, res) => {
            console.log("❌ 代理错误:", err);
          });
        },
      },
    },
  },
});
